<?php

$s = "We are happy.";
$arr=str_split($s); //转化成数组
foreach($arr as &$item){
    if($item==' '){//执行替换操作
        $item='%20';
    }
}
var_dump(implode('',$arr));    //数组转化成字符串返回
